package site.fsyj.util;

import lombok.extern.slf4j.Slf4j;

import java.awt.*;


/**
 * 用于演示通知栏信息
 * @author fsyj on 2022/3/7
 */
@Slf4j
public class TrayUtil {
    public static void displayTray(String title, String message) {
        // Obtain only one instance of the SystemTray object
        SystemTray tray = SystemTray.getSystemTray();

        // If the icon is a file
        Image image = Toolkit.getDefaultToolkit().getImage("");

        TrayIcon trayIcon = new TrayIcon(image);
        //Let the system resize the image if needed
        trayIcon.setImageAutoSize(true);
        //Set tooltip text for the tray icon
        trayIcon.setToolTip("System tray icon demo");
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            log.error("通知加载错误");
        }

        trayIcon.setImageAutoSize(true);

        trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO);
    }
}
